package com.skynet.backend.auth.sys.vo;

import com.skynet.backend.auth.sys.entity.SysMenuEntity;

import java.util.List;
import java.util.stream.Collectors;

public class SysMenuItemVoFactory {

    private SysMenuItemVoFactory() {

    }

    private static SysMenuItemVO create(SysMenuEntity sysMenuEntity) {
        return new SysMenuItemVO(
                sysMenuEntity.getMenuName(),
                sysMenuEntity.getMenuIcon(),
                sysMenuEntity.getMenuLink(),
                mapToSysMenuItem(sysMenuEntity.getChildren()),
                sysMenuEntity.getIsHome() == 1,
                sysMenuEntity.getIsGroup() == 1
        );
    }

    public static List<SysMenuItemVO> mapToSysMenuItem(List<SysMenuEntity> children) {
        return children != null && children.size() > 0 ? children.stream()
                .map(SysMenuItemVoFactory::create)
                .collect(Collectors.toList()) : null;
    }

}
